package top.xiaoshuaila.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.xiaoshuaila.pojo.Position;
import top.xiaoshuaila.pojo.RespBean;
import top.xiaoshuaila.service.IPositionService;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小帅啦
 * @since 2021-05-01
 */
@RestController
@Api(tags = "职位管理")
@RequestMapping("/system/basic/pos")
public class PositionController {

    @Autowired
    private IPositionService positionService;
    @ApiOperation("获取所有职位信息")
    @GetMapping("/")
    private List<Position>getAllPositions(){
        return positionService.list();
    }

    @ApiOperation("添加职位")
    @PostMapping("/")
    private RespBean addPositions(@RequestBody Position position){
        position.setCreateDate(LocalDateTime.now());
        if(positionService.save(position))
            return RespBean.success("添加成功!");
        return RespBean.error("添加失败!");
    }

    @ApiOperation("更新职位")
    @PutMapping("/")
    private RespBean updatePositions(@RequestBody Position position){
        if(positionService.updateById(position))
            return RespBean.success("更新成功!");
        return RespBean.error("更新失败!");
    }

    @ApiOperation("删除职位")
    @DeleteMapping("/{id}")
    private RespBean deletePositions(@PathVariable Integer id){
        if(positionService.removeById(id))
            return RespBean.success("删除成功!");
        return RespBean.error("删除失败!");
    }

    @ApiOperation("批量删除职位")
    @DeleteMapping("/")
    private RespBean deletePositions(Integer[]ids){
        if(positionService.removeByIds(Arrays.asList(ids)))
            return RespBean.success("删除成功!");
        return RespBean.error("删除失败!");
    }

}
